﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using SenseTimeTracker.Properties;
using StedySoft.SenseSDK;

namespace SenseTimeTracker.Main
{
	public class AboutForm : ITranslucentForm
	{
		private const char copyChar = '\u00a9';
		private string copyrightInfo = "Copyright " + copyChar + "2010 BerlinSoft";
		private Bitmap logo;
		private Icon icon;

		public AboutForm()
		{
			Dock = DockStyle.Fill;
			WindowState = FormWindowState.Maximized;
			ControlBox = false;
			Assembly assembly = Assembly.GetExecutingAssembly();

			logo = new Bitmap(assembly.GetManifestResourceStream("SenseTimeTracker.Resources.Logo.bmp"));
			icon = new Icon(assembly.GetManifestResourceStream("SenseTimeTracker.Resources.TimeTrackerIcon.ico"), 128, 128);
		}

		protected override void OnClick(EventArgs e)
		{
			Close();
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			ImageAttributes immageAttr = new ImageAttributes();
			immageAttr.SetColorKey(Color.Magenta, Color.Magenta);
			Rectangle logoRect = new Rectangle((Width - logo.Width) / 2, 300, logo.Width, logo.Height);
			e.Graphics.DrawImage(logo, logoRect, 0, 0, logo.Width, logo.Height, GraphicsUnit.Pixel, immageAttr);
			e.Graphics.DrawIcon(icon, 120, 150);

			using (Brush brush = new SolidBrush(Color.White))
			using (Font font = new Font("HelveticaNeue LT 35 Thin", 7f, FontStyle.Regular))
			using (Font versionFont = new Font("HelveticaNeue LT 35 Thin", 6f, FontStyle.Regular))
			{
				string version = string.Format("{0}: {1}", Resources.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().Version);
				SizeF versionSize = e.Graphics.MeasureString(version, versionFont);
				e.Graphics.DrawString(version, versionFont, brush, logoRect.Right - versionSize.Width, logoRect.Bottom + 2);
				SizeF copyrightSize = e.Graphics.MeasureString(copyrightInfo, font);
				e.Graphics.DrawString(copyrightInfo, font, brush, (Width - copyrightSize.Width) / 2, (Height - copyrightSize.Height) / 2);
			}
		}
	}
}
